package cert.utils;

import sun.misc.BASE64Decoder;
import sun.security.pkcs.PKCS10;

public class CSRUtility {

	public static PKCS10 ReadCSR(String request) {

		request = request
				.replace("-----BEGIN NEW CERTIFICATE REQUEST-----", "");
		request = request.replace("-----END NEW CERTIFICATE REQUEST-----", "");

		PKCS10 pkcs10 = null;
		try {

			BASE64Decoder decoder = new BASE64Decoder();
			byte[] decodedBytes = decoder.decodeBuffer(request);

			pkcs10 = new PKCS10(decodedBytes);

			return pkcs10;

		} catch (Exception e) {
			e.printStackTrace();
		}
		return pkcs10;
	}
}
